"""
构建一个Tool

"""
from langchain import SerpAPIWrapper
from langchain.tools import Tool,tool

import calendar
import dateutil.parser as parser
from datetime import date

"""第一种方法"""
search  = SerpAPIWrapper()
# 构建一个tool 这个tool 从funtion中获取
tools=[
  Tool.from_function(
    func=search.run,
    name="Search",
    description="useful for when you need to answer questions about current events. Input should be a search query"
  )
]

"""第二种方法"""
@tool("weekday")
def weekday(date_Str:str) -> str:
    """Convert data to weekday name"""
    d = parser.parse(date_Str)
    return calendar.day_name[d.weekday()]
tools += [weekday]



# 将 tools 导出为模块级别的变量
__all__ = ['tools']